package com.htht.smartschool.util.log;

import org.apache.log4j.Logger;

public class FileLog implements ILog {
	private static Logger commonLogger = null;
	private static Logger locationLogger = null;
	private static Logger orderLogger = null;
	private static Logger eventLogger = null;
	private static Logger userLogger = null;
	
	public FileLog() {
		
	}
	
	@Override
	public void log(String usercode, LogType type, String content) {
		 
		switch (type) {
		case common:
			commonLog(usercode, content);
			break;
		case location:
			locationLog(usercode, content);
			break;
		case order:
			orderLog(usercode, content);
			break;
		case event:
			eventLog(usercode, content);
			break;
		case user:
			userLog(usercode, content);
			break;	
		default:
			break;
		}
	}

	@Override
	public void log(String content) {
		 
		log("common", LogType.common, content);
	}

	private void commonLog(String usercode, String content) {
		if (commonLogger == null) {
			commonLogger = Logger.getLogger("common");
		}
		commonLogger.info(String.format("%1$s, %2$s", usercode, content));
	}

	private void locationLog(String usercode, String content) {
		if (locationLogger == null) {
			locationLogger = Logger.getLogger("location");
		}
		locationLogger.info(String.format("%1$s, %2$s", usercode, content));
	}

	private void eventLog(String usercode, String content) {
		if (eventLogger == null) {
			eventLogger = Logger.getLogger("event");
		}
		eventLogger.info(String.format("%1$s, %2$s", usercode, content));
	}

	private void userLog(String usercode, String content) {
		if (userLogger == null) {
			userLogger = Logger.getLogger("user");
		}
		userLogger.info(String.format("%1$s, %2$s", usercode, content));
	}
	
	private void orderLog(String usercode, String content) {
		if (orderLogger == null) {
			orderLogger = Logger.getLogger("order");
		}
		orderLogger.info(String.format("%1$s, %2$s", usercode, content));
	}
}
